package com.teleca.jamendo.dialog;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import android.app.Activity;
import android.os.RemoteException;
import android.util.Log;

import com.beem.project.beem.service.VVPacketAdapter;
import com.beem.project.beem.service.aidl.IXmppFacade;
import com.btf.push.GPSPacket;

public class DistanceUsersDialog extends LoadingDialog<String, Collection<GPSPacket.Item>>{
	    	
	    	ArrayList<com.btf.push.GPSPacket.Item> items ;
	    	private  IXmppFacade mXmppFacade;
	
			public DistanceUsersDialog(Activity activity, int loadingMsg,
					int failMsg) {
				super(activity, loadingMsg, failMsg);
				// TODO Auto-generated constructor stub
			}
			
			public DistanceUsersDialog(Activity activity, int loadingMsg,
					int failMsg,IXmppFacade mXmppFacade) {
				super(activity, loadingMsg, failMsg);
				// TODO Auto-generated constructor stub
				this.mXmppFacade = mXmppFacade;
			}
	
			@Override
			public Collection<com.btf.push.GPSPacket.Item> doInBackground(
					String... params) {
				// TODO Auto-generated method stub
				VVPacketAdapter res;
				try {
					res = mXmppFacade.conllectVVPacket(new VVPacketAdapter(new GPSPacket()));
					//Debug.getDebugInstance().log("DownloadAvatarTask conllectVVPacket");
					
					if (res!=null && res.getPacket()!=null) {
						GPSPacket newCard = (GPSPacket) res.getPacket();
						return newCard.getRosterItems();
					}else {
						return null;
					}
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
				//return null;
			}
	
			@Override
			public void doStuffWithResult(
					Collection<com.btf.push.GPSPacket.Item> result) {
				// TODO Auto-generated method stub
				items = new ArrayList<com.btf.push.GPSPacket.Item>();
				for (Iterator iterator = result.iterator(); iterator.hasNext();) {
					com.btf.push.GPSPacket.Item item = (com.btf.push.GPSPacket.Item) iterator.next();
					items.add(item);
					Log.i("VV","dis "+ item.toXML());
				}
//				imageAdapter = new ImageAdapter(mActivity,items);
//				updateLayout(imageAdapter);
			}
	    	
	    
}

